home *** CD-ROM | disk | FTP | other *** search
- #ifndef GFILE_H
- #define GFILE_H
- #include <stdio.h>
- #include "common.h"
- #include "manager.h"
- #include "graph.h"
-
- /* graph_file reader and saver - the actual father of all image format classes
- * It supports line-by-line image reading and writing
- * (But not the whole image at once).
- * This feature cause some difficulties for us (see formats.cpp)
- * and, possibly, for you; but it solves problem of
- *
- * !! NOT ENOUGH MEMORY !!!
- *
- * Note: you can only sequentially read the lines of image,
- * normally (for compressed images) it is too difficult
- * to jump to random line #
- *
- * Written by E. Podvoysky & Kiselev J. CZ 1994.
- */
-
-
-
- #define BUFF_SIZE 30000 // size of object's input buffer
- enum image_type {MONOIMG,COLOR16IMG,GRAY256IMG,COLOR256IMG,TRUECOLORIMG};
- enum image_extention_type {NO_EXTENTION,
- MONOGIF, // versus NO_EXTENTION
- COLOR16_2PIXEL,COLOR16_1PIXEL,COLOR16_PLANE,
- GRAY_PALETTE, // versus NO_EXTENTION
- RGB15,RGB16,BGR24,RGB24,BGRA32,RGBPLANE24};
-
- /* image forms that are used in formats and in our procedures: */
- /* MONOIMG,NO_EXTENTION - bit per pixel
- * MONOIMG,MONOGIF - byte (though only 0 or 1 in value) per pixel
- * COLOR16IMG, COLOR16_2PIXEL - two pixels in each byte
- * (most significant bits - left pixel)
- * COLOR16IMG, COLOR16_1PIXEL - byte (value range: 0..15) per pixel
- * COLOR16IMG, COLOR16_PLANE - four planes of one dispaly row
- * are stored in one array (16 colors EGA/VGA video mode)
- * GRAY256IMG, NO_EXTENTION - byte (256 shades) per pixel
- * GRAY256IMG, GRAY_PALETTE - byte per pixel, shades are defined in palette
- * absolutely the same as COLOR256IMG
- * COLOR256IMG - byte per pixel (256 colors)
- * TRUECOLORIMG RGB15 - high color 32k colors
- * TRUECOLORIMG RGB16 - high color 64k colors
- * TRUECOLORIMG RGB24 - true color,
- * TRUECOLORIMG BGRA32 - B, G, R and Alfa - 4 bytes per pixel (see Targa format descr.)
- * TRUECOLORIMG RGBPLANE24 - all line's pixels R values, then G values and B.
- */
-
- int get_bitsperpixel(image_type it,image_extention_type iet);
-
- extern long minheap;
- // minimal size of heap which is to be free (normally 70000L);
-
- class graph_file_abstract { // some graphics format file reader are
- protected:
- FILE *the_file;
- BYTE *buffer;
- WORD buff_offset;
- BOOL usebuffer;
- void (*line2standart)(BYTE*,BYTE*,int);
- public:
- BOOL file_ok;
- BOOL top_to_bottom,left_to_right; // pixels order
- int width,height;
- int bytesperline;
- int line_n; //current line number
- long colors;
-
- graph_file_abstract();
- virtual ~graph_file_abstract(); // closes file and disposes buffer
- long image_size();
- void init_buffer(BOOL usebuffer_);
- // procedure for constructors, call when file is opened!
- // if (usebuffer_) allocates buffer
- // otherwise - bufferizes file
- // WARNING:
- // in the last case procedure calls fseek(0,SEEK_SET);
- // for savers call only just after file was opened!
-
- };
-
- class graph_file_reader: public graph_file_abstract {
- protected:
- long data_begin; // don't forget to set it, descendants!!!
- public:
- BGRpalette palette;
- image_type source_type;
- image_extention_type source_ext_type;
-
- BYTE *source_line; // get readed line from here
- BYTE *standart_line; // get converted to our internal form
- // (by get_stand_line()) line from here
-
- graph_file_reader() {}; // formal
- graph_file_reader(char *fname); // opens the file
-
- virtual void seek_start(); // seek to image itself start
- // normally constructors calls seek_start()
-
- virtual void fresh_buffer(); // if buffer is almost cleared
- // reads new portion of data
- int get_stand_line(); // returns -1 if file is already finished
- virtual int get_next_line(); // returns -1 if file is already finished
- };
-
- /* we convert data in one of 3 our internal formats
- * (just for simplicity of further processing).
- * MONO bit per pixel, byte per pixel and RGB lines
- * You may use faster get_next_line() and get data from source_line,
- * and bother yourself by CASEs for all possible image forms
- * or call get_stand_line() and get converted data from standart_line
- */
-
- class graph_file_saver: public graph_file_abstract { // some graphics format file saver
- protected:
- BGRpalette *palette; // keeps only pointer on pallette
- public:
- image_type dest_type;
- image_extention_type dest_ext_type;
-
- graph_file_saver() {}; //formal
- graph_file_saver(char *fname,
- BOOL usebuffer_,
- image_type dest_type_,
- image_extention_type dest_ext_type_,
- int width_,int height_,
- BGRpalette* pal);
- // object keeps only pointer on pallette
- // so do not change or delete palette before delete object
- virtual void update_palette(BGRpalette *pal) {};
- int put_stand_line(BYTE *line); // returns -1 if file is finished
- virtual int put_next_line(BYTE *line); //returns -1 if some error occurs
- virtual void flush_buffer(); // writes acumulated buffer in file
- };
-
-
- /* abstract image storage, may be in file or in memory
- * or, possibly in expanded memory, if you write proprer descendant
- * it simply stores image line after line, and then returns
- * line you want.
- */
- enum memory_type {convRAM, exRAM, DISK, UNKNOWN};
-
- class image_keeper: public graph_file_abstract {
- protected:
- BYTE *current_line; // is used if data are stored in file
- BYTE **lines;
- USER_HANDLE *lines_ext;
- char *tmp_filename;
- public:
- memory_type where;
- image_type im_type;
- BGRcolortype *palette;
-
- image_keeper(memory_type where_, // set UNKNOWN if you want kepper to select
- image_type im_type_,
- int width_,int height_,BGRcolortype * pal,
- BOOL top_to_bottom_);
- ~image_keeper();
- BYTE * give_line(int line_no); // read stored line
- void store_line(BYTE * source);
- void replace_line(int line_no,BYTE * source);
- };
-
-
- #endif
-